<%--
  Created by IntelliJ IDEA.
  User: jackiechan
  Date: 2021/9/3
  Time: 09:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
</head>
<body>

<table border="1px">

    <tr>
        <th>stuid</th>
        <th>stuName</th>
        <th>stuGender</th>
        <th>stuPhone</th>
        <th>stbornDateuid</th>
        <th>stuEmail</th>
        <th>stuAddress</th>
        <th>gradeId</th>
        <th>操作</th>
    </tr>

    <c:forEach items="${pagedata.dataList}" var="stu" varStatus="vs">
        <c:if test="${vs.index % 2==0}">
            <tr style="color:red;">
        </c:if>

        <c:if test="${vs.index % 2==1}">
            <tr style="color:blue;">
        </c:if>

        <td>${stu.stuId}</td>
        <td>${stu.stuName}</td>
        <td>${stu.stuGender}</td>
        <td>${stu.stuPhone}</td>
        <td>${stu.bornDate}</td>
        <td>${stu.stuEmail}</td>
        <td>${stu.stuAddress}</td>
        <td>${stu.gradeId}</td>
        <td>
            <a href="./studentoperater?option=updatepage&stuId=${stu.stuId}">编辑</a>
            <a href="./studentoperater?option=delete&stuId=${stu.stuId}">删除</a>
        </td>
        </tr>

    </c:forEach>

</table>

<c:if test="${pagedata.pageNum >1}">
    <a href="./studentoperater?option=querylist&pageNum=${pagedata.pageNum-1}&pageSize=${pagedata.pageSize}"> 上一页</a>
</c:if>

<%--
显示页码,按照我们的规则,至少是在第六页的时候前面才会显示...
如果在某一页,这一页前面超过了 5 也就会有.. 后面有三个就显示.. 但是前 3 页不做处理
--%>

<c:if test="${pagedata.pageNum >=6}">
    <a href="./studentoperater?option=querylist&pageNum=1&pageSize=${pagedata.pageSize}">1</a>
    <a href="./studentoperater?option=querylist&pageNum=2&pageSize=${pagedata.pageSize}">2</a>
    ...
    <a href="./studentoperater?option=querylist&pageNum=${pagedata.pageNum-2}&pageSize=${pagedata.pageSize}">${pagedata.pageNum-2}</a>
    <a href="./studentoperater?option=querylist&pageNum=${pagedata.pageNum-1}&pageSize=${pagedata.pageSize}">${pagedata.pageNum-1}</a>
    <span style="color: red">${pagedata.pageNum}</span>
    <c:if test="${pagedata.totalPage-pagedata.pageNum >=1}">
        <a href="./studentoperater?option=querylist&pageNum=${pagedata.pageNum+1}&pageSize=${pagedata.pageSize}">${pagedata.pageNum+1}</a>
    </c:if>
    <c:if test="${pagedata.totalPage-pagedata.pageNum >=2}">
        <a href="./studentoperater?option=querylist&pageNum=${pagedata.pageNum+2}&pageSize=${pagedata.pageSize}">${pagedata.pageNum+2}</a>
    </c:if>
    <c:if test="${pagedata.totalPage-pagedata.pageNum >3}">
        ...
    </c:if>

</c:if>
<%--
小于等于 5 显示 1-5,但是当前第几页不知道,当前页要红色
--%>
<c:if test="${pagedata.pageNum <=5}">
    <c:if test="${pagedata.totalPage >5}">
        <c:choose>
            <c:when test="${pagedata.pageNum ==1}">
                <span style="color: red">${pagedata.pageNum}</span>
                <a href="./studentoperater?option=querylist&pageNum=2&pageSize=${pagedata.pageSize}">2</a>
                <a href="./studentoperater?option=querylist&pageNum=3&pageSize=${pagedata.pageSize}">3</a>
                <a href="./studentoperater?option=querylist&pageNum=4&pageSize=${pagedata.pageSize}">4</a>
                <a href="./studentoperater?option=querylist&pageNum=5&pageSize=${pagedata.pageSize}">5</a>

            </c:when>
            <c:when test="${pagedata.pageNum ==2}">
                <a href="./studentoperater?option=querylist&pageNum=1&pageSize=${pagedata.pageSize}">1</a>
                <span style="color: red">${pagedata.pageNum}</span>
                <a href="./studentoperater?option=querylist&pageNum=3&pageSize=${pagedata.pageSize}">3</a>
                <a href="./studentoperater?option=querylist&pageNum=4&pageSize=${pagedata.pageSize}">4</a>
                <a href="./studentoperater?option=querylist&pageNum=5&pageSize=${pagedata.pageSize}">5</a>

            </c:when>
            <c:when test="${pagedata.pageNum ==3}">
                <a href="./studentoperater?option=querylist&pageNum=1&pageSize=${pagedata.pageSize}">1</a>
                <a href="./studentoperater?option=querylist&pageNum=2&pageSize=${pagedata.pageSize}">2</a>
                <span style="color: red">${pagedata.pageNum}</span>
                <a href="./studentoperater?option=querylist&pageNum=4&pageSize=${pagedata.pageSize}">4</a>
                <a href="./studentoperater?option=querylist&pageNum=5&pageSize=${pagedata.pageSize}">5</a>
            </c:when>
            <c:when test="${pagedata.pageNum ==4}">
                <a href="./studentoperater?option=querylist&pageNum=1&pageSize=${pagedata.pageSize}">1</a>
                <a href="./studentoperater?option=querylist&pageNum=2&pageSize=${pagedata.pageSize}">2</a>
                <a href="./studentoperater?option=querylist&pageNum=3&pageSize=${pagedata.pageSize}">3</a>
                <span style="color: red">${pagedata.pageNum}</span>
                <a href="./studentoperater?option=querylist&pageNum=5&pageSize=${pagedata.pageSize}">5</a>

                <c:if test="${pagedata.totalPage-pagedata.pageNum >=2}">
                    <a href="./studentoperater?option=querylist&pageNum=${pagedata.pageNum+2}&pageSize=${pagedata.pageSize}">${pagedata.pageNum+2}</a>
                </c:if>
                <c:if test="${pagedata.totalPage-pagedata.pageNum >=3}">
                    ...
                </c:if>

            </c:when>
            <c:when test="${pagedata.pageNum ==5}">
                <a href="./studentoperater?option=querylist&pageNum=1&pageSize=${pagedata.pageSize}">1</a>
                <a href="./studentoperater?option=querylist&pageNum=2&pageSize=${pagedata.pageSize}">2</a>
                <a href="./studentoperater?option=querylist&pageNum=3&pageSize=${pagedata.pageSize}">3</a>
                <a href="./studentoperater?option=querylist&pageNum=4&pageSize=${pagedata.pageSize}">4</a>
                <span style="color: red">${pagedata.pageNum}</span>
                <c:if test="${pagedata.totalPage-pagedata.pageNum >=1}">
                    <a href="./studentoperater?option=querylist&pageNum=${pagedata.pageNum+1}&pageSize=${pagedata.pageSize}">${pagedata.pageNum+1}</a>
                </c:if>
                <c:if test="${pagedata.totalPage-pagedata.pageNum >=2}">
                    <a href="./studentoperater?option=querylist&pageNum=${pagedata.pageNum+2}&pageSize=${pagedata.pageSize}">${pagedata.pageNum+2}</a>
                </c:if>
                <c:if test="${pagedata.totalPage-pagedata.pageNum >=3}">
                    ...
                </c:if>

            </c:when>

        </c:choose>
    </c:if>

    <c:if test="${pagedata.totalPage<=5}">
        <c:if test="${pagedata.totalPage >=1}">
            <c:if test="${pagedata.pageNum ==1}">
                <span style="color:red;">1</span>
            </c:if>
            <c:if test="${pagedata.pageNum !=1}">
                <a href="./studentoperater?option=querylist&pageNum=1&pageSize=${pagedata.pageSize}">1</a>
            </c:if>
        </c:if>
        <c:if test="${pagedata.totalPage >=2}">
            <c:if test="${pagedata.pageNum ==2}">
                <span style="color:red;">2</span>
            </c:if>

            <c:if test="${pagedata.pageNum !=2}">

                <a href="./studentoperater?option=querylist&pageNum=2&pageSize=${pagedata.pageSize}">2</a>
            </c:if>

        </c:if>
        <c:if test="${pagedata.totalPage >=3}">
            <c:if test="${pagedata.pageNum ==3}">
                <span style="color:red;">3</span>
            </c:if>

            <c:if test="${pagedata.pageNum !=3}">

                <a href="./studentoperater?option=querylist&pageNum=3&pageSize=${pagedata.pageSize}">3</a>
            </c:if>


        </c:if>
        <c:if test="${pagedata.totalPage >=4}">

            <c:if test="${pagedata.pageNum ==4}">
                <span style="color:red;">4</span>
            </c:if>

            <c:if test="${pagedata.pageNum !=4}">

                <a href="./studentoperater?option=querylist&pageNum=4&pageSize=${pagedata.pageSize}">4</a>
            </c:if>


        </c:if>
        <c:if test="${pagedata.totalPage >=5}">
            <c:if test="${pagedata.pageNum ==5}">
                <span style="color:red;">5</span>
            </c:if>

            <c:if test="${pagedata.pageNum !=5}">
                <a href="./studentoperater?option=querylist&pageNum=5&pageSize=${pagedata.pageSize}">5</a>
            </c:if>


        </c:if>

    </c:if>


</c:if>


<c:if test="${pagedata.pageNum < pagedata.totalPage}">
    <a href="./studentoperater?option=querylist&pageNum=${pagedata.pageNum+1}&pageSize=${pagedata.pageSize}"> 下一页</a>
</c:if>
</body>
</html>
